package tests_dao;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import dao.CrudService;
import dao.CrudServiceImpl;
import entities.Currency;
import entities.ExchangeRate;

public class UpdateTest
{
	CrudService	crud_service	= new CrudServiceImpl();
	SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
	
	@Test
	public void updateExchangeRateTest () throws ParseException
	{
		final Date date = sdf.parse("10-11-2014");
		final String currency_code = "ABC";
		final BigDecimal new_rate = new BigDecimal("666.00");
		
		crud_service.updateExchangeRate (currency_code, date, new_rate);
		
		ExchangeRate result = crud_service.readExchangeRate (currency_code, date);
		
		
		Assert.assertEquals(result.getExchange_rate(), new_rate);
		
	}
	
	
	@BeforeClass
	public void beforeClass()
	{
		crud_service.clearDataBase();
	}
	
	@BeforeMethod
	public void beforeMethod() throws ParseException
	{
		ExchangeRate ex1 = new ExchangeRate(sdf.parse("10-11-2014"), new Currency("ABC", "abc currency"), 1, new BigDecimal(6));
		ExchangeRate ex2 = new ExchangeRate(sdf.parse("10-12-2014"), new Currency("XYZ", "xyz currency"), 1, new BigDecimal(3));
		

		crud_service.addExchangeRate(ex1);
		crud_service.addExchangeRate(ex2);
	}
	
	@AfterClass
	public void afterClass ()
	{
		crud_service.clearDataBase();
	}
	
	
	
	
	
	
	
}
